package com.gao.shiro.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.web.bind.annotation.PostMapping;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @author gaofeng
 * @date 2022年07月02日 18:39
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 配置Swagger的Docket bean实例
     *
     * @return springfox.documentation.spring.web.plugins.Docket
     */
    @Bean
    public Docket docket(Environment environment) {
        // 设置要显示swagger的环境
        Profiles dev = Profiles.of("dev");
        // 获取项目的环境，判断是否处在设定的环境当中
        boolean flag = environment.acceptsProfiles(dev);

        return new Docket(DocumentationType.SWAGGER_2).
                apiInfo(apiInfo())
                // 是否启用swagger，默认为true
//                .enable(false)
                // 分组，如果想要多个分组，要创建多个docket实例
                .groupName("gaofeng")
                .select()
                // 配置接口要扫描的方式
//                .apis(RequestHandlerSelectors.basePackage("com.gao.shiro.demo.controller"))
//                .apis(RequestHandlerSelectors.withClassAnnotation(PostMapping.class))
                // 过滤
//                .paths(PathSelectors.regex(""))
                .build();
    }

    /**
     * 配置apiInfo
     *
     * @return springfox.documentation.service.ApiInfo
     */
    public ApiInfo apiInfo() {
        return new ApiInfo("高枫创建的API文档",
                "Api Documentation",
                "v1.0",
                "urn:tos",
                // 作者信息
                new Contact("gaofeng", "", "gf21522@163.com"),
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0"
               );
    }


}
